package com.zq.recruit.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zq.common.util.Result;
import com.zq.recruit.dao.entity.JobPosition;
import com.zq.recruit.dao.entity.UserCollection;
import com.zq.recruit.service.UserCollectionService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @Author 张乔
 * @Date 2025/4/5 19:49
 */
@RestController
@RequestMapping("/recruit/userCollection")
public class UserCollectionController {
    @Resource
    private UserCollectionService userCollectionService;

    @PostMapping("/add")
    public Result<Object> addUserCollection(@RequestBody UserCollection userCollection){
        userCollectionService.getExistById(userCollection);
      userCollection.setCreateTime(new Date());
         userCollectionService.save(userCollection);
    return Result.success();
    }


    @GetMapping("/getInfoByUserId/{id}")
    public Result<Object> getInfoByUserId(@PathVariable("id") Integer id){
        List<JobPosition> pageInfo =userCollectionService.getInfoByUserId(id);
        return     Result.successData(pageInfo);
    }

    @DeleteMapping("/deleteById/{id}/{userId}")
    public Result<Object> deleteIds(@PathVariable("id") Integer id,@PathVariable("userId") Integer userId){
        LambdaQueryWrapper<UserCollection> lambdaQuery = new LambdaQueryWrapper<>();
        lambdaQuery.eq(id!=null,UserCollection::getJobId,id)
                .eq(userId!=null,UserCollection::getUserId,userId);
      userCollectionService.remove(lambdaQuery);
        return     Result.success();
    }


}
